package xyz.zyt123.hikvideo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;
import xyz.zyt123.hikvideo.bean.Capture;
import xyz.zyt123.hikvideo.bean.User;
import xyz.zyt123.hikvideo.common.AjaxResult;
import xyz.zyt123.hikvideo.common.PageQuery;
import xyz.zyt123.hikvideo.service.CaptureService;
import xyz.zyt123.hikvideo.service.SysLogService;

/**
 * @author zhuyuntao
 */
@RestController
@RequestMapping("/api/v1/capture")
public class CaptureController {
  @Autowired
  private CaptureService captureService;
  @Autowired
  private SysLogService sysLogService;

  @PostMapping("/page")
  public AjaxResult<Page<Capture>> page(@RequestBody PageQuery pageQuery) {
    return AjaxResult.success(captureService.page(new Page<>(pageQuery.getCurrent(), pageQuery.getSize())));
  }

  @GetMapping("/{id}")
  public AjaxResult<Capture> get(@PathVariable("id") Integer id) {
    return AjaxResult.success(captureService.getById(id));
  }


  @DeleteMapping("/{id}")
  public AjaxResult<Void> delete(@PathVariable("id") Integer id, @SessionAttribute("user") User user) {
    captureService.removeById(id);
    sysLogService.saveSysLog(user, "删除抓拍");
    return AjaxResult.success();
  }
}
